<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

/**
 * 数据可视化
 */
Route::group(['prefix' => 'admin', 'namespace' => 'Api'], function () {
    //会员性别统计
    Route::get('sex_total', 'EchartController@sex_total')->name('sex_total');
    //省份分布统计
    Route::get('province_total', 'EchartController@province_total')->name('province_total');

    Route::post('bind', 'EchartController@bind')->name('bind');

});

/**
 * 微信接口
 */
Route::group(['namespace' => 'Wechat'], function () {
    Route::any('/wechat', 'WechatController@serve');
});


/**
 * 小米前端vue.js路由
 */
Route::group(['namespace' => 'Api'], function () {
    //前端首页
    Route::get('/', 'HomeController@index');

    Route::any('authenticate', 'AuthenticateController@authenticate');

    //商品
    Route::group(['prefix' => 'product'], function () {
        //分类
        Route::get('category', 'ProductController@category');
        //显示商品列表
        Route::get('/', 'ProductController@index');
        //显示商品详情
        Route::get('show/{id}', 'ProductController@show');
        //搜索
        Route::get('search', 'ProductController@search');
    });

    //中间键
    Route::group(['middleware' => 'jwt.auth'], function () {
        //购物车管理
        Route::group(['prefix' => 'cart'], function () {
            Route::get('/', 'CartController@index');
            Route::post('/', 'CartController@store');
            Route::delete('/', 'CartController@destroy');
            Route::patch('/', 'CartController@change_num');
        });

        //订单管理
        Route::group(['prefix' => 'order'], function () {
            //下单
            Route::get('check_out', 'OrderController@check_out')->name('order.check_out');
            //生成订单
            Route::post('store', 'OrderController@store')->name('order.store');
            //支付订单
            Route::get('show_pay', 'OrderController@show_pay')->name('order.show_pay');
            //订单列表
            Route::get('/', 'OrderController@index');
            //查看订单详情
            Route::get('show', 'OrderController@show')->name('order.show');
            //取消订单
            Route::delete('{id}', 'OrderController@destroy');
        });

        //地址管理
        Route::group(['prefix' => 'address'], function () {
            //管理地址
            Route::get('manage', 'AddressController@manage')->name('address.manage');
            //设置默认地址
            Route::patch('default_address', 'AddressController@default_address')->name('address.default_address');
        });
        Route::resource('address', 'AddressController');
    });


});